package com.woniu.payback_font.web;

import com.github.pagehelper.PageInfo;
import com.woniu.payback_font.entity.Load;
import com.woniu.payback_font.entity.Repayment;
import com.woniu.payback_font.result.ResponseResult;
import com.woniu.payback_font.service.RepaymentService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Api("还款接口api")
@RestController
@RequestMapping("repayment")
public class RepaymentController {

    @Autowired
    private RepaymentService repaymentService;


    @GetMapping("/findAll")
    public ResponseResult<PageInfo<Repayment>> showLoan(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum ,
                                                        @RequestParam(value = "pageSize",defaultValue = "10")Integer pageSize){
        ResponseResult result = null;
        PageInfo<Repayment> info = repaymentService.findAll(pageNum, pageSize);
        if(info==null){
            result=new ResponseResult(204,"查询失败");
        }else{
            result=new ResponseResult(200,"查询成功");
            result.setData(info);
        }
        return result;
    }


    @GetMapping("/findOne")
    public ResponseResult<PageInfo<Repayment>> findOne(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum ,
                                                        @RequestParam(value = "pageSize",defaultValue = "5")Integer pageSize,
                                                       String aUid){
        ResponseResult result = null;
        PageInfo<Repayment> info = repaymentService.findOne(pageNum, pageSize,aUid);
        if(info==null){
            result=new ResponseResult(204,"查询失败");
        }else{
            result=new ResponseResult(200,"查询成功");
            result.setData(info);
        }
        return result;
    }
}
